<?php
require('../database/db.php');
include("../../tool/UpFileTool.class.php");
$mysql=new mysql();
// 需传参数
$ordersid=$_REQUEST['ordersid'];
$shopid=$_REQUEST['shopid'];
$userid=$_REQUEST['userid'];
$star=$_REQUEST['star'];
$comment=$_REQUEST['comment'];
$images=$_FILES['images'];
// 需传参数 end
if ($shopid!='' && $userid!='' && in_array($star, array(0 ,1 ,2 ,3 ,4 ,5))) {
	$flag = true;
	$sql = "INSERT INTO evaluate (shopid,userid,star) VALUES (".$shopid.",".$userid.",".$star.")";
	$query = $mysql->query($sql);
	if ($mysql->affected_rows()<=0) {
		$flag = false;
	}
	$id = $mysql->insert_id();
	if ($comment!='') {
		$sql = "UPDATE evaluate set comment='".$comment."' where id=".$id;
		$query = $mysql->query($sql);
		if ($mysql->affected_rows()<=0) {
			$flag = false;
		}
	}
	if ($images[name][0]!='') {
		$UpFileTool=new UpFileTool('images');
		$UpFileTool->multiImage($w=500, $h=500,$sumbimage='../../sumbimage', $srcimage='../../srcimage');
		$images=$UpFileTool->multiSumbImage;
		$srcimages=$UpFileTool->multiSrcImage;

		$sql = "UPDATE evaluate set images='".$images."',srcimages='".$srcimages."' where id=".$id;
		$query = $mysql->query($sql);
		if ($mysql->affected_rows()<=0) {
			$flag = false;
		}
	}
	if ($flag == false && $id != '') {
		$sql = "DELETE from evaluate where id=".$id;
		$query = $mysql->query($sql);
		$arr = array('code' => 300, 'tip' =>'添加评论失败');
	}elseif ($flag == false && $id == '') {
		$arr = array('code' => 300, 'tip' =>'添加评论失败');
	}else{
		$state=5;

	    $srat1=mysql_query("update goodsorders set state='".$state."' where ordersid='".$ordersid."'");

		// 调用信息推送接口
		$url = "http://120.24.0.10/xzpf/api/jpush/jpush.php?state=".$state."&ordersid=".$ordersid;
		file_get_contents($url);
		// 调用信息推送接口 end
		$arr = array('code' => 200, 'tip' =>'添加评论成功');
	}
}else{
	$arr = array('code' => 100, 'tip' =>'参数传入有误,必传参数:商家id=>shopid;用户id=>userid;评级星级=>star(0-5);可传参数:评价内容=>comment;图片=>images');
}
echo json_encode($arr);
?>